package main

import "fmt"

/*
  提示：defer注册要延时的函数时该函数所有的参数都需要确定其值
*/

func cacl(index string, a, b int) int {
	ret := a + b
	fmt.Println(index, a, b, ret)
	return ret
}

func main() {
	x := 1
	y := 2
	defer cacl("AA", x, cacl("A", x, y))
	x = 10
	defer cacl("BB", x, cacl("B", x, y))
}

/*
   注册顺序
      defer cacl("AA", x, cacl("A", x, y))
      defer cacl("BB", x, cacl("B", x, y))
   执行顺序
      1、 defer cacl("BB", x, cacl("B", x, y))
	  2、 defer cacl("AA", x, cacl("A", x, y))
*/

/*  打印
    1、cacl("A",x,y)  A 1 2 3
    2、cacl("B",x,y) B 10 2 12
	3、cacl("BB",x,12) BB 10 12 22
	4、cacl("AA",x,3) AA 1 3 4
*/
